home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / php / pear / HTML / Progress / UI.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  33.3 KB  |  917 lines

  1. <?php
  2. // +----------------------------------------------------------------------+
  3. // | PHP Version 4                                                        |
  4. // +----------------------------------------------------------------------+
  5. // | Copyright (c) 1997-2003 The PHP Group                                |
  6. // +----------------------------------------------------------------------+
  7. // | This source file is subject to version 3.0 of the PHP license,       |
  8. // | that is bundled with this package in the file LICENSE, and is        |
  9. // | available at through the world-wide-web at                           |
  10. // | http://www.php.net/license/3_0.txt.                                  |
  11. // | If you did not receive a copy of the PHP license and are unable to   |
  12. // | obtain it through the world-wide-web, please send a note to          |
  13. // | license@php.net so we can mail you a copy immediately.               |
  14. // +----------------------------------------------------------------------+
  15. // | Author: Laurent Laville <pear@laurent-laville.org>                   |
  16. // +----------------------------------------------------------------------+
  17. //
  18. // $Id: UI.php,v 1.1 2003/11/15 18:27:09 thesaur Exp $
  19.  
  20. /**
  21.  * The HTML_Progress_UI class provides a basic look and feel 
  22.  * implementation of a progress bar.
  23.  *
  24.  * @version    1.0
  25.  * @author     Laurent Laville <pear@laurent-laville.org>
  26.  * @access     public
  27.  * @category   HTML
  28.  * @package    HTML_Progress
  29.  * @license    http://www.php.net/license/3_0.txt  PHP License 3.0
  30.  * @todo       better aligment renders when auto-size progress is false
  31.  */
  32.  
  33. require_once ('HTML/Common.php');
  34.  
  35. class HTML_Progress_UI extends HTML_Common
  36. {
  37.     /**
  38.      * Whether the progress bar is horizontal or vertical.
  39.      * The default is horizontal.
  40.      *
  41.      * @var        integer
  42.      * @since      1.0
  43.      * @access     private
  44.      * @see        getOrientation(), setOrientation()
  45.      */
  46.     var $_orientation;
  47.  
  48.     /**
  49.      * Whether the progress bar is filled in 'natural' or 'reverse' way.
  50.      * The default fill way is 'natural'.
  51.      *
  52.      * <ul>
  53.      * <li>since 0.5 : 'way'  =  bar fill way 
  54.      *   <ul>
  55.      *     <li>with Progress Bar Horizontal, 
  56.      *              natural way is : left to right
  57.      *        <br />reverse way is : right to left
  58.      *     <li>with Progress Bar Vertical, 
  59.      *              natural way is : down to up
  60.      *        <br />reverse way is : up to down
  61.      *   </ul>
  62.      * </ul>
  63.      *
  64.      * @var        string
  65.      * @since      1.0
  66.      * @access     private
  67.      * @see        getFillWay(), setFillWay()
  68.      */
  69.     var $_fillWay;
  70.  
  71.     /**
  72.      * The cell count of the progress bar. The default is 10.
  73.      *
  74.      * @var        integer
  75.      * @since      1.0
  76.      * @access     private
  77.      * @see        getCellCount(), setCellCount()
  78.      */
  79.     var $_cellCount;
  80.  
  81.     /**
  82.      * The progress bar's structure 
  83.      *
  84.      * <ul>
  85.      * <li>['cell']
  86.      *     <ul>
  87.      *     <li>since 1.0 : 'id'             =  cell identifier mask
  88.      *     <li>since 1.0 : 'class'          =  css class selector
  89.      *     <li>since 0.1 : 'width'          =  cell width
  90.      *     <li>since 0.1 : 'height'         =  cell height
  91.      *     <li>since 0.1 : 'active-color'   =  active color
  92.      *     <li>since 0.1 : 'inactive-color' =  inactive color
  93.      *     <li>since 0.1 : 'spacing'        =  cell spacing
  94.      *     <li>since 0.6 : 'color'          =  foreground color
  95.      *     <li>since 0.6 : 'font-size'      =  font size
  96.      *     <li>since 0.6 : 'font-family'    =  font family
  97.      *     </ul>
  98.      * <li>['border']
  99.      *     <ul>
  100.      *     <li>since 1.0 : 'class'  =  css class selector
  101.      *     <li>since 0.1 : 'width'  =  border width
  102.      *     <li>since 0.1 : 'style'  =  border style
  103.      *     <li>since 0.1 : 'color'  =  border color
  104.      *     </ul>
  105.      * <li>['string']
  106.      *     <ul>
  107.      *     <li>sicne 1.0 : 'id'                =  string identifier
  108.      *     <li>since 0.6 : 'width'             =  with of progress string
  109.      *     <li>since 0.6 : 'height'            =  height of progress string
  110.      *     <li>since 0.1 : 'font-family'       =  font family
  111.      *     <li>since 0.1 : 'font-size'         =  font size
  112.      *     <li>since 0.1 : 'color'             =  font color
  113.      *     <li>since 0.6 : 'background-color'  =  background color
  114.      *     <li>since 0.6 : 'align'             =  horizontal align  (left, center, right, justify)
  115.      *     <li>since 0.6 : 'valign'            =  vertical align  (top, bottom, left, right)
  116.      *     </ul>
  117.      * <li>['progress']
  118.      *     <ul>
  119.      *     <li>since 1.0 : 'class'             =  css class selector
  120.      *     <li>since 0.1 : 'background-color'  =  bar background color
  121.      *     <li>since 1.0 : 'auto-size'         = compute best progress size
  122.      *     <li>since 0.1 : 'width'             =  bar width
  123.      *     <li>since 0.1 : 'height'            =  bar height
  124.      *     </ul>
  125.      * </ul>
  126.      *
  127.      * @var        array
  128.      * @since      1.0
  129.      * @access     private
  130.      * @see        HTML_Progress::toArray()
  131.      */
  132.     var $_progress = array();
  133.  
  134.     /**
  135.      * External Javascript file to override internal default code
  136.      *
  137.      * @var        string
  138.      * @since      1.0
  139.      * @access     private
  140.      * @see        getScript(), setScript()
  141.      */
  142.     var $_script;
  143.  
  144.     /**
  145.      * Package name used by Error_Raise functions
  146.      *
  147.      * @var        string
  148.      * @since      1.0
  149.      * @access     private
  150.      */
  151.     var $_package;
  152.  
  153.  
  154.     /**
  155.      * The progress bar's UI model class constructor
  156.      *
  157.      * Constructor Summary
  158.      *
  159.      * o Creates a natural horizontal progress bar that displays ten cells/units.
  160.      *   <code>
  161.      *   $html = new HTML_Progress_UI();
  162.      *   </code>
  163.      *
  164.      * o Creates a natural horizontal progress bar with the specified cell count, 
  165.      *   which cannot be less than 1 (minimum), but has no maximum limit.
  166.      *   <code>
  167.      *   $html = new HTML_Progress_UI($cell);
  168.      *   </code>
  169.      *
  170.      * @since      1.0
  171.      * @access     public
  172.      * @throws     HTML_PROGRESS_ERROR_INVALID_INPUT
  173.      */
  174.     function HTML_Progress_UI()
  175.     {
  176.         $this->_package = 'HTML_Progress_UI';
  177.         Error_Raise::initialize($this->_package, array('HTML_Progress', '_getErrorMessage'));
  178.  
  179.         $args = func_get_args();
  180.  
  181.         switch (count($args)) {
  182.          case 1:
  183.             /*   int cell  */
  184.             if (!is_int($args[0])) {
  185.                 return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
  186.                     array('var' => '$cell',
  187.                           'was' => $args[0],
  188.                           'expected' => 'integer',
  189.                           'paramnum' => 1), PEAR_ERROR_TRIGGER);
  190.  
  191.             } elseif ($args[0] < 1) {
  192.                 return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
  193.                     array('var' => '$cell',
  194.                           'was' => $args[0],
  195.                           'expected' => 'greater or equal 1',
  196.                           'paramnum' => 1), PEAR_ERROR_TRIGGER);
  197.             }
  198.             $this->_cellCount = $args[0];
  199.             break;
  200.          default:
  201.             $this->_cellCount = 10;
  202.             break;
  203.         }
  204.         $this->_orientation = HTML_PROGRESS_BAR_HORIZONTAL;
  205.         $this->_fillWay = 'natural';
  206.         $this->_script = null;              // uses internal javascript code
  207.  
  208.         $this->_progress = array(
  209.             'cell' => 
  210.                 array(
  211.                     'id' => "progressCell%01s",
  212.                     'class' => "cell",
  213.                     'active-color' => "#006600",
  214.                     'inactive-color' => "#CCCCCC",
  215.                     'font-family' => "Courier, Verdana",
  216.                     'font-size' => 8,
  217.                     'color' => "#000000",
  218.                     'width' => 15,
  219.                     'height' => 20,
  220.                     'spacing' => 2
  221.                 ),
  222.             'border' => 
  223.                 array(
  224.                     'class' => "progressBarBorder",
  225.                     'width' => 0,
  226.                     'style' => "solid",
  227.                     'color' => "#000000"
  228.                 ),
  229.             'string' => 
  230.                 array(
  231.                     'id' => "installationProgress",
  232.                     'width' => 50,
  233.                     'font-family' => "Verdana, Arial, Helvetica, sans-serif",
  234.                     'font-size' => 12,
  235.                     'color' => "#000000",
  236.                     'background-color' => "#FFFFFF",
  237.                     'align' => "right",
  238.                     'valign' => "right"
  239.                 ),
  240.             'progress' => 
  241.                 array(
  242.                     'class' => "progressBar",
  243.                     'background-color' => "#FFFFFF",
  244.                     'auto-size' => true
  245.                 )
  246.         );
  247.         $this->_updateProgressSize();   // updates the new size of progress bar
  248.     }
  249.  
  250.     /**
  251.      * Returns HTML_PROGRESS_BAR_HORIZONTAL or HTML_PROGRESS_BAR_VERTICAL,
  252.      * depending on the orientation of the progress bar.
  253.      * The default orientation is HTML_PROGRESS_BAR_HORIZONTAL.
  254.      *
  255.      * @return     integer
  256.      * @since      1.0
  257.      * @access     public
  258.      * @see        setOrientation()
  259.      */
  260.     function getOrientation()
  261.     {
  262.         return $this->_orientation;
  263.     }
  264.  
  265.     /**
  266.      * Sets the progress bar's orientation, which must be HTML_PROGRESS_BAR_HORIZONTAL
  267.      * or HTML_PROGRESS_BAR_VERTICAL.
  268.      * The default orientation is HTML_PROGRESS_BAR_HORIZONTAL.
  269.      *
  270.      * @param      integer   $orient        Orientation (horizontal or vertical)
  271.      *
  272.      * @return     void
  273.      * @since      1.0
  274.      * @access     public
  275.      * @throws     HTML_PROGRESS_ERROR_INVALID_INPUT
  276.      * @see        getOrientation()
  277.      */
  278.     function setOrientation($orient)
  279.     {
  280.         if (!is_int($orient)) {
  281.             return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
  282.                 array('var' => '$orient',
  283.                       'was' => gettype($orient),
  284.                       'expected' => 'integer',
  285.                       'paramnum' => 1), PEAR_ERROR_TRIGGER);
  286.  
  287.         } elseif (($orient != HTML_PROGRESS_BAR_HORIZONTAL) && 
  288.                   ($orient != HTML_PROGRESS_BAR_VERTICAL)) {
  289.             return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
  290.                 array('var' => '$orient',
  291.                       'was' => $orient,
  292.                       'expected' => HTML_PROGRESS_BAR_HORIZONTAL.' | '.
  293.                                     HTML_PROGRESS_BAR_VERTICAL,
  294.                       'paramnum' => 1), PEAR_ERROR_TRIGGER);
  295.         }
  296.  
  297.         $previous = $this->_orientation;    // gets previous orientation
  298.         $this->_orientation = $orient;      // sets the new orientation
  299.  
  300.         if ($previous != $orient) {
  301.             // if orientation has changed, we need to swap cell width and height
  302.             $w = $this->_progress['cell']['width'];
  303.             $h = $this->_progress['cell']['height'];
  304.  
  305.             $this->_progress['cell']['width']  = $h;
  306.             $this->_progress['cell']['height'] = $w;
  307.                                             
  308.             $this->_updateProgressSize();   // updates the new size of progress bar
  309.         }
  310.     }
  311.  
  312.     /**
  313.      * Returns 'natural' or 'reverse', depending of the fill way of progress bar.
  314.      * For horizontal progress bar, natural way is from left to right, and reverse 
  315.      * way is from right to left.
  316.      * For vertical progress bar, natural way is from down to up, and reverse 
  317.      * way is from up to down.
  318.      * The default fill way is 'natural'.
  319.      *
  320.      * @return     string
  321.      * @since      1.0
  322.      * @access     public
  323.      * @see        setFillWay()
  324.      */
  325.     function getFillWay()
  326.     {
  327.         return $this->_fillWay;
  328.     }
  329.  
  330.     /**
  331.      * Sets the progress bar's fill way, which must be 'natural' or 'reverse'.
  332.      * The default fill way is 'natural'.
  333.      *
  334.      * @param      string    $way           fill direction (natural or reverse)
  335.      *
  336.      * @return     void
  337.      * @since      1.0
  338.      * @access     public
  339.      * @throws     HTML_PROGRESS_ERROR_INVALID_INPUT
  340.      * @see        getFillWay()
  341.      */
  342.     function setFillWay($way)
  343.     {
  344.         if (!is_string($way)) {
  345.             return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
  346.                 array('var' => '$way',
  347.                       'was' => gettype($way),
  348.                       'expected' => 'string',
  349.                       'paramnum' => 1), PEAR_ERROR_TRIGGER);
  350.  
  351.         } elseif ((strtolower($way) != 'natural') && (strtolower($way) != 'reverse')) {
  352.             return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
  353.                 array('var' => '$way',
  354.                       'was' => $way,
  355.                       'expected' => 'natural | reverse',
  356.                       'paramnum' => 1), PEAR_ERROR_TRIGGER);
  357.         }
  358.         $this->_fillWay = strtolower($way);
  359.     }
  360.  
  361.     /**
  362.      * Returns the number of cell in the progress bar. The default value is 10.
  363.      *
  364.      * @return     integer
  365.      * @since      1.0
  366.      * @access     public
  367.      * @see        setCellCount()
  368.      */
  369.     function getCellCount()
  370.     {
  371.         return $this->_cellCount;
  372.     }
  373.  
  374.     /**
  375.      * Sets the number of cell in the progress bar
  376.      *
  377.      * @param      integer   $cells         Cell count on progress bar
  378.      *
  379.      * @return     void
  380.      * @since      1.0
  381.      * @access     public
  382.      * @throws     HTML_PROGRESS_ERROR_INVALID_INPUT
  383.      * @see        getCellCount()
  384.      * @tutorial   beginner.pkg#look-and-feel.cell-style
  385.      */
  386.     function setCellCount($cells)
  387.     {
  388.         if (!is_int($cells)) {
  389.             return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
  390.                 array('var' => '$cells',
  391.                       'was' => gettype($cells),
  392.                       'expected' => 'integer',
  393.                       'paramnum' => 1), PEAR_ERROR_TRIGGER);
  394.  
  395.         } elseif ($cells < 1) {
  396.             return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
  397.                 array('var' => '$cells',
  398.                       'was' => $cells,
  399.                       'expected' => 'greater or equal 1',
  400.                       'paramnum' => 1), PEAR_ERROR_TRIGGER);
  401.         }
  402.         $this->_cellCount = $cells;
  403.  
  404.         $this->_updateProgressSize();   // updates the new size of progress bar
  405.     }
  406.  
  407.     /**
  408.      * Returns the common and private cell attributes. Assoc array (defaut) or string
  409.      *
  410.      * @param      bool      $asString      (optional) whether to return the attributes as string 
  411.      *
  412.      * @return     mixed
  413.      * @since      1.0
  414.      * @access     public
  415.      * @throws     HTML_PROGRESS_ERROR_INVALID_INPUT
  416.      * @see        setCellAttributes()
  417.      */
  418.     function getCellAttributes($asString = false)
  419.     {
  420.         if (!is_bool($asString)) {
  421.             return Error_Raise::exception($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT,
  422.                 array('var' => '$asString',
  423.                       'was' => gettype($asString),
  424.                       'expected' => 'boolean',
  425.                       'paramnum' => 1));
  426.         }
  427.  
  428.         $attr = $this->_progress['cell'];
  429.  
  430.         if ($asString) {
  431.             return $this->_getAttrString($attr);
  432.         } else {
  433.             return $attr;
  434.         }
  435.     }
  436.  
  437.     /**
  438.      * Sets the cell attributes for an existing cell.
  439.      *
  440.      * Defaults are:
  441.      * <ul>
  442.      * <li>Common :
  443.      *     <ul>
  444.      *     <li>id             = progressCell%01s
  445.      *     <li>class          = cell
  446.      *     <li>spacing        = 2
  447.      *     <li>active-color   = #006600
  448.      *     <li>inactive-color = #CCCCCC
  449.      *     <li>font-family    = Courier, Verdana
  450.      *     <li>font-size      = lowest value from cell width, cell height, and font size
  451.      *     <li>color          = #000000
  452.      *     <li>Horizontal Bar :
  453.      *         <ul>
  454.      *         <li>width      = 15
  455.      *         <li>height     = 20
  456.      *         </ul>
  457.      *     <li>Vertical Bar :
  458.      *         <ul>
  459.      *         <li>width      = 20
  460.      *         <li>height     = 15
  461.      *         </ul>
  462.      *     </ul>
  463.      * </ul>
  464.      *
  465.      * @param      mixed     $attributes    Associative array or string of HTML tag attributes
  466.      * @param      int       $cell          (optional) Cell index
  467.      *
  468.      * @return     void
  469.      * @since      1.0
  470.      * @access     public
  471.      * @throws     HTML_PROGRESS_ERROR_INVALID_INPUT
  472.      * @see        getCellAttributes()
  473.      * @tutorial   beginner.pkg#look-and-feel.cell-style
  474.      */
  475.     function setCellAttributes($attributes, $cell = null)
  476.     {
  477.         if (!is_null($cell)) {
  478.             if (!is_int($cell)) {
  479.                 return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
  480.                     array('var' => '$cell',
  481.                           'was' => gettype($cell),
  482.                           'expected' => 'integer',
  483.                           'paramnum' => 1), PEAR_ERROR_TRIGGER);
  484.  
  485.             } elseif ($cell < 0) {
  486.                 return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
  487.                     array('var' => '$cell',
  488.                           'was' => $cell,
  489.                           'expected' => 'positive',
  490.                           'paramnum' => 1), PEAR_ERROR_TRIGGER);
  491.  
  492.             } elseif ($cell >= $this->getCellCount()) {
  493.                 return Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
  494.                     array('var' => '$cell',
  495.                           'was' => $cell,
  496.                           'expected' => 'less than '.$this->getCellCount(),
  497.                           'paramnum' => 1), PEAR_ERROR_TRIGGER);
  498.             }
  499.  
  500.             $this->_updateAttrArray($this->_progress['cell'][$cell], $this->_parseAttributes($attributes));
  501.         } else {
  502.             $this->_updateAttrArray($this->_progress['cell'], $this->_parseAttributes($attributes));
  503.         }
  504.         
  505.         $font_size   = $this->_progress['cell']['font-size'];
  506.         $cell_width  = $this->_progress['cell']['width'];
  507.         $cell_height = $this->_progress['cell']['height'];
  508.         $margin = ($this->getOrientation() == HTML_PROGRESS_BAR_HORIZONTAL) ? 0 : 3;
  509.  
  510.         $font_size = min(min($cell_width, $cell_height) - $margin, $font_size);
  511.         $this->_progress['cell']['font-size'] = $font_size;
  512.  
  513.         $this->_updateProgressSize();   // updates the new size of progress bar
  514.     }
  515.  
  516.     /**
  517.      * Returns the progress bar's border attributes. Assoc array (defaut) or string.
  518.      *
  519.      * @param      bool      $asString      (optional) whether to return the attributes as string 
  520.      *
  521.      * @return     mixed
  522.      * @since      1.0
  523.      * @access     public
  524.      * @throws     HTML_PROGRESS_ERROR_INVALID_INPUT
  525.      * @see        setBorderAttributes()
  526.      */
  527.     function getBorderAttributes($asString = false)
  528.     {
  529.         if (!is_bool($asString)) {
  530.             return Error_Raise::exception($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT,
  531.                 array('var' => '$asString',
  532.                       'was' => gettype($asString),
  533.                       'expected' => 'boolean',
  534.                       'paramnum' => 1));
  535.         }
  536.  
  537.         $attr = $this->_progress['border'];
  538.  
  539.         if ($asString) {
  540.             return $this->_getAttrString($attr);
  541.         } else {
  542.             return $attr;
  543.         }
  544.     }
  545.  
  546.     /**
  547.      * Sets the progress bar's border attributes.
  548.      *
  549.      * Defaults are:
  550.      * <ul>
  551.      * <li>class   = progressBarBorder
  552.      * <li>width   = 0
  553.      * <li>style   = solid
  554.      * <li>color   = #000000
  555.      * </ul>
  556.      *
  557.      * @param      mixed     $attributes    Associative array or string of HTML tag attributes
  558.      *
  559.      * @return     void
  560.      * @since      1.0
  561.      * @access     public
  562.      * @see        getBorderAttributes()
  563.      * @tutorial   beginner.pkg#look-and-feel.border-style
  564.      * @example    bluesand.php             A thin solid border to a horizontal progress bar
  565.      */
  566.     function setBorderAttributes($attributes)
  567.     {
  568.         $this->_updateAttrArray($this->_progress['border'], $this->_parseAttributes($attributes));
  569.  
  570.         $this->_updateProgressSize();   // updates the new size of progress bar
  571.     }
  572.  
  573.     /**
  574.      * Returns the string attributes. Assoc array (defaut) or string.
  575.      *
  576.      * @param      bool      $asString      (optional) whether to return the attributes as string 
  577.      *
  578.      * @return     mixed
  579.      * @since      1.0
  580.      * @access     public
  581.      * @throws     HTML_PROGRESS_ERROR_INVALID_INPUT
  582.      * @see        setStringAttributes()
  583.      */
  584.     function getStringAttributes($asString = false)
  585.     {
  586.         if (!is_bool($asString)) {
  587.             return Error_Raise::exception($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT,
  588.                 array('var' => '$asString',
  589.                       'was' => gettype($asString),
  590.                       'expected' => 'boolean',
  591.                       'paramnum' => 1));
  592.         }
  593.  
  594.         $attr = $this->_progress['string'];
  595.  
  596.         if ($asString) {
  597.             return $this->_getAttrString($attr);
  598.         } else {
  599.             return $attr;
  600.         }
  601.     }
  602.  
  603.     /**
  604.      * Sets the string attributes.
  605.      *
  606.      * Defaults are:
  607.      * <ul>
  608.      * <li>id                = installationProgress
  609.      * <li>width             = 50
  610.      * <li>font-family       = Verdana, Arial, Helvetica, sans-serif
  611.      * <li>font-size         = 12
  612.      * <li>color             = #000000
  613.      * <li>background-color  = #FFFFFF
  614.      * <li>align             = right
  615.      * <li>Horizontal Bar :
  616.      *     <ul>
  617.      *     <li>valign        = right
  618.      *     </ul>
  619.      * <li>Vertical Bar :
  620.      *     <ul>
  621.      *     <li>valign        = bottom
  622.      *     </ul>
  623.      * </ul>
  624.      *
  625.      * @param      mixed     $attributes    Associative array or string of HTML tag attributes
  626.      *
  627.      * @return     void
  628.      * @since      1.0
  629.      * @access     public
  630.      * @see        getStringAttributes()
  631.      * @tutorial   beginner.pkg#look-and-feel.string-style
  632.      */
  633.     function setStringAttributes($attributes)
  634.     {
  635.         $this->_updateAttrArray($this->_progress['string'], $this->_parseAttributes($attributes));
  636.     }
  637.  
  638.     /**
  639.      * Returns the progress attributes. Assoc array (defaut) or string.
  640.      *
  641.      * @param      bool      $asString      (optional) whether to return the attributes as string 
  642.      *
  643.      * @return     mixed
  644.      * @since      1.0
  645.      * @access     public
  646.      * @throws     HTML_PROGRESS_ERROR_INVALID_INPUT
  647.      * @see        setProgressAttributes()
  648.      */
  649.     function getProgressAttributes($asString = false)
  650.     {
  651.         if (!is_bool($asString)) {
  652.             return Error_Raise::exception($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT,
  653.                 array('var' => '$asString',
  654.                       'was' => gettype($asString),
  655.                       'expected' => 'boolean',
  656.                       'paramnum' => 1));
  657.         }
  658.  
  659.         $attr = $this->_progress['progress'];
  660.  
  661.         if ($asString) {
  662.             return $this->_getAttrString($attr);
  663.         } else {
  664.             return $attr;
  665.         }
  666.     }
  667.  
  668.     /**
  669.      * Sets the common progress bar attributes.
  670.      *
  671.      * Defaults are:
  672.      * <ul>
  673.      * <li>class             = progressBar
  674.      * <li>background-color  = #FFFFFF
  675.      * <li>auto-size         = true
  676.      * <li>Horizontal Bar :
  677.      *     <ul>
  678.      *     <li>width         = (cell_count * (cell_width + cell_spacing)) + cell_spacing
  679.      *     <li>height        = cell_height + (2 * cell_spacing)
  680.      *     </ul>
  681.      * <li>Vertical Bar :
  682.      *     <ul>
  683.      *     <li>width         = cell_width + (2 * cell_spacing)
  684.      *     <li>height        = (cell_count * (cell_height + cell_spacing)) + cell_spacing
  685.      *     </ul>
  686.      * </ul>
  687.      *
  688.      * @param      mixed     $attributes    Associative array or string of HTML tag attributes
  689.      *
  690.      * @return     void
  691.      * @since      1.0
  692.      * @access     public
  693.      * @see        getProgressAttributes()
  694.      * @tutorial   beginner.pkg#look-and-feel.progress-style
  695.      */
  696.     function setProgressAttributes($attributes)
  697.     {
  698.         $this->_updateAttrArray($this->_progress['progress'], $this->_parseAttributes($attributes));
  699.     }
  700.  
  701.     /**
  702.      * Get the javascript code to manage progress bar.
  703.      *
  704.      * @return     string                   JavaScript URL or inline code to manage progress bar
  705.      * @since      0.5
  706.      * @access     public
  707.      * @see        setScript()
  708.      * @author     Stefan Neufeind <pear.neufeind@speedpartner.de> Contributor.
  709.      *             See details on thanks section of README file.
  710.      * @author     Christian Wenz <wenz@php.net> Helper.
  711.      *             See details on thanks section of README file.
  712.      */
  713.     function getScript()
  714.     {
  715.         if (!is_null($this->_script)) {
  716.             return $this->_script;   // URL to the linked Progress JavaScript
  717.         }
  718.  
  719.         $js = <<< JS
  720. var isDom = document.getElementById?true:false;
  721. var isIE  = document.all?true:false;
  722. var isNS4 = document.layers?true:false;
  723. var cellCount = %cellCount%;
  724.  
  725. function setprogress(pIdent, pValue, pString, pDeterminate)
  726. {
  727.         if (isDom)
  728.             prog = document.getElementById(pIdent+'%installationProgress%');
  729.         if (isIE)
  730.             prog = document.all[pIdent+'%installationProgress%'];
  731.         if (isNS4)
  732.             prog = document.layers[pIdent+'%installationProgress%'];
  733.     if (prog != null) 
  734.         prog.innerHTML = pString;
  735.  
  736.         if (pValue == pDeterminate) {
  737.         for (i=0; i < cellCount; i++) {
  738.                 showCell(i, pIdent, "hidden");    
  739.             }
  740.         }
  741.         if ((pDeterminate > 0) && (pValue > 0)) {
  742.             i = (pValue-1) % cellCount;
  743.             showCell(i, pIdent, "visible");    
  744.         } else {
  745.             for (i=pValue-1; i >=0; i--) {
  746.                 showCell(i, pIdent, "visible");    
  747.             }
  748.     }
  749. }
  750.  
  751. function showCell(pCell, pIdent, pVisibility)
  752. {
  753.     if (isDom)
  754.         document.getElementById(pIdent+'%progressCell%'+pCell+'A').style.visibility = pVisibility;
  755.     if (isIE)
  756.         document.all[pIdent+'%progressCell%'+pCell+'A'].style.visibility = pVisibility;
  757.     if (isNS4)
  758.         document.layers[pIdent+'%progressCell%'+pCell+'A'].style.visibility = pVisibility;
  759.  
  760. }
  761.  
  762. JS;
  763.         $cellAttr = $this->getCellAttributes();
  764.         $attr = trim(sprintf($cellAttr['id'], '   '));
  765.         $stringAttr = $this->getStringAttributes();
  766.         $js = str_replace("%cellCount%", $this->getCellCount(), $js);
  767.         $js = str_replace("%installationProgress%", $stringAttr['id'], $js);
  768.         $js = str_replace("%progressCell%", $attr, $js);
  769.          
  770.         return $js;
  771.     }
  772.  
  773.     /**
  774.      * Set the external JavaScript code (file) to manage progress element.
  775.      *
  776.      * @param      string    $url           URL to the linked Progress JavaScript
  777.      *
  778.      * @return     void
  779.      * @since      1.0
  780.      * @access     public
  781.      * @throws     HTML_PROGRESS_ERROR_INVALID_INPUT
  782.      * @see        getScript()
  783.      */
  784.     function setScript($url)
  785.     {
  786.         if (!is_null($url)) {
  787.             if (!is_string($url)) {
  788.                 Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'exception',
  789.                     array('var' => '$url',
  790.                           'was' => gettype($url),
  791.                           'expected' => 'string',
  792.                           'paramnum' => 1), PEAR_ERROR_TRIGGER);
  793.  
  794.             } elseif (!is_file($url) || $url == '.' || $url == '..') {
  795.                 Error_Raise::raise($this->_package, HTML_PROGRESS_ERROR_INVALID_INPUT, 'error',
  796.                     array('var' => '$url',
  797.                           'was' => $url.' file does not exists',
  798.                           'expected' => 'javascript file exists',
  799.                           'paramnum' => 1), PEAR_ERROR_TRIGGER);
  800.             }
  801.         }
  802.  
  803.         /*
  804.          - since version 0.5.0,
  805.          - default javascript code comes from getScript() method
  806.          - but may be overrided by external file. 
  807.         */
  808.         $this->_script = $url;
  809.     }
  810.  
  811.     /**
  812.      * Get the cascading style sheet to put inline on HTML document
  813.      *
  814.      * @return     object                   HTML_CSS instance
  815.      * @since      0.2
  816.      * @access     public
  817.      * @author     Stefan Neufeind <pear.neufeind@speedpartner.de> Contributor.
  818.      *             See details on thanks section of README file.
  819.      */
  820.     function &getStyle()
  821.     {
  822.         include_once ('HTML/CSS.php');
  823.         
  824.         $progressAttr = $this->getProgressAttributes();
  825.         $borderAttr = $this->getBorderAttributes();
  826.         $stringAttr = $this->getStringAttributes();
  827.         $cellAttr = $this->getCellAttributes();
  828.         $orient = $this->getOrientation();
  829.         
  830.         $css = new HTML_CSS();
  831.  
  832.         $css->setStyle('.'.$progressAttr['class'], 'background-color', $progressAttr['background-color']);
  833.         $css->setStyle('.'.$progressAttr['class'], 'width', $progressAttr['width'].'px');
  834.         $css->setStyle('.'.$progressAttr['class'], 'height', $progressAttr['height'].'px');
  835.         $css->setStyle('.'.$progressAttr['class'], 'position', 'relative');
  836.         $css->setStyle('.'.$progressAttr['class'], 'left', '0px');
  837.         $css->setStyle('.'.$progressAttr['class'], 'top', '0px');
  838.  
  839.         $css->setSameStyle('.'.$borderAttr['class'], '.'.$progressAttr['class']);
  840.         $css->setStyle('.'.$borderAttr['class'], 'border-width', $borderAttr['width'].'px');
  841.         $css->setStyle('.'.$borderAttr['class'], 'border-style', $borderAttr['style']);
  842.         $css->setStyle('.'.$borderAttr['class'], 'border-color', $borderAttr['color']);
  843.  
  844.         $css->setStyle('.'.$stringAttr['id'], 'width', $stringAttr['width'].'px');
  845.         if (isset($stringAttr['height'])) {
  846.             $css->setStyle('.'.$stringAttr['id'], 'height', $stringAttr['height'].'px');
  847.         }
  848.         $css->setStyle('.'.$stringAttr['id'], 'text-align', $stringAttr['align']);
  849.         $css->setStyle('.'.$stringAttr['id'], 'font-family', $stringAttr['font-family']);
  850.         $css->setStyle('.'.$stringAttr['id'], 'font-size', $stringAttr['font-size'].'px');
  851.         $css->setStyle('.'.$stringAttr['id'], 'color', $stringAttr['color']);
  852.         $css->setStyle('.'.$stringAttr['id'], 'background-color', $stringAttr['background-color']);
  853.  
  854.         $css->setStyle('.'.$cellAttr['class'].'I', 'width', $cellAttr['width'].'px');
  855.         $css->setStyle('.'.$cellAttr['class'].'I', 'height', $cellAttr['height'].'px');
  856.         $css->setStyle('.'.$cellAttr['class'].'I', 'font-family', $cellAttr['font-family']);
  857.         $css->setStyle('.'.$cellAttr['class'].'I', 'font-size', $cellAttr['font-size'].'px');
  858.  
  859.         if ($orient == HTML_PROGRESS_BAR_HORIZONTAL) {
  860.             $css->setStyle('.'.$cellAttr['class'].'I', 'float', 'left'); 
  861.         }
  862.         if ($orient == HTML_PROGRESS_BAR_VERTICAL) {
  863.             $css->setStyle('.'.$cellAttr['class'].'I', 'float', 'none'); 
  864.         }
  865.         $css->setSameStyle('.'.$cellAttr['class'].'A', '.'.$cellAttr['class'].'I');
  866.  
  867.         $css->setStyle('.'.$cellAttr['class'].'I', 'background-color', $cellAttr['inactive-color']);
  868.         $css->setStyle('.'.$cellAttr['class'].'A', 'background-color', $cellAttr['active-color']);
  869.         $css->setStyle('.'.$cellAttr['class'].'A', 'visibility', 'hidden');
  870.  
  871.         if (isset($cellAttr['background-image'])) {
  872.             $css->setStyle('.'.$cellAttr['class'].'A', 'background-image', 'url("'.$cellAttr['background-image'].'")');
  873.             $css->setStyle('.'.$cellAttr['class'].'A', 'background-repeat', 'no-repeat');
  874.         }
  875.         
  876.         return $css;
  877.     }
  878.  
  879.     /**
  880.      * Updates the new size of progress bar, depending of cell size, cell count
  881.      * and border width.
  882.      *
  883.      * @since      1.0
  884.      * @access     private
  885.      * @see        setOrientation(), setCellCount(), setCellAttributes(),
  886.      *             setBorderAttributes()
  887.      */
  888.     function _updateProgressSize()
  889.     {
  890.         if (!$this->_progress['progress']['auto-size']) {
  891.             return;
  892.         }
  893.  
  894.         $cell_width   = $this->_progress['cell']['width'];
  895.         $cell_height  = $this->_progress['cell']['height'];
  896.         $cell_spacing = $this->_progress['cell']['spacing'];
  897.  
  898.         $border_width = $this->_progress['border']['width'];
  899.  
  900.         $cell_count = $this->_cellCount;
  901.  
  902.         if ($this->getOrientation() == HTML_PROGRESS_BAR_HORIZONTAL) {
  903.             $w = ($cell_count * ($cell_width + $cell_spacing)) + $cell_spacing;
  904.             $h = $cell_height + (2 * $cell_spacing);
  905.         }
  906.         if ($this->getOrientation() == HTML_PROGRESS_BAR_VERTICAL) {
  907.             $w  = $cell_width + (2 * $cell_spacing);
  908.             $h  = ($cell_count * ($cell_height + $cell_spacing)) + $cell_spacing;
  909.         } 
  910.  
  911.         $attr = array ('width' => $w, 'height' => $h);
  912.  
  913.         $this->_updateAttrArray($this->_progress['progress'], $attr);
  914.     }
  915. }
  916.  
  917. ?>